/*
 * Created by BAC IT Deustche Bank
 * User: Sergio Vasquez
 * Date: 6/12/2009
 * Time: 2:57 PM
 * 
 * Description:
 * 
 */
using System;
using System.Collections.Generic;
using System.Data;
using IScheduler.Core.Managers;
using IScheduler.Core.Persistence.Base;


namespace IScheduler.Core.Persistence
{
	/// <summary>
	/// Description of HolidayPersistence.
	/// </summary>
	public class HolidayData : DataAccessLayer
	{
		/// <summary>
		/// Get holiday list from the database
		/// </summary>
		/// <returns></returns>
		public IList<Holiday> GetHolidayList()
		{
			IList<Holiday> holidays = null;
			string sqlCommand = "SELECT dt_holiday, nm_holiday FROM is_holiday";
			
			try
			{
				IDbCommand command = GetCommandQuery(sqlCommand);
				using (IDataReader reader = command.ExecuteReader())
	            {
					if(reader != null)
					{
						holidays = new List<Holiday>();
						
						Holiday holiday;
		            	
						while (reader.Read())
		                {
		            		holiday = new Holiday();
		            		holiday.Date = TryParseReaderToDateTime(reader["dt_holiday"]);
		            		holiday.Name = TryParseReaderToString(reader["nm_holiday"]);
		            		holidays.Add (holiday);
		            	}
					}
	            }	
			}
			catch (PersistenceException e)
			{
				throw new PersistenceException("An error occurred during getting holiday list.", this.ToString(), e);
			}			
			return holidays;
		}
	}
}
